﻿using Anke.SHManage.IDAL;
using Anke.SHManage.Model;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Anke.SHManage.BLL
{
    public class MobileTaskBLL
    {
        MobileTaskDAL idal = new MobileTaskDAL();

        //IMobileTaskDAL idal = DataAccess.GetMobileTaskDAL();
        public List<MobileTaskInfo> GetMobileTaskListBy(string userCode, string taskCode, ref string errorMsg)
        {
            return idal.GetMobileTaskListBy(userCode, taskCode, ref errorMsg);
        }

        /// <summary>
        /// 20151109增加为PAD，根据版本号和标识查询
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="version"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public List<I_Material> GetMainDictionary(string tableName, string version, string state)
        {
            return idal.GetMainDictionary(tableName, version, state);
        }

        ///// <summary>
        ///// 20151210增加PAD保存收费
        ///// </summary>
        ///// <param name="info"></param>
        ///// <param name="patientChargeLogInfo"></param>
        ///// <param name="errorMsg"></param>
        ///// <returns></returns>
        //public bool MobileSavePatientCharge(M_PatientCharge info, M_PatientChargeLog patientChargeLogInfo, ref string errorMsg)
        //{
        //    //2018-12-11 zch 
        //    if (info != null && info.InvoiceNumber != null)
        //    {
        //        new I_InvoiceApprovalBLL().DealUsedInvoiceRecord(info.InvoiceNumber);
        //    }

        //    return idal.MobileSavePatientCharge(info, patientChargeLogInfo, ref errorMsg);
        //}

        /// <summary>
        /// 20151210增加PAD保存收费
        /// 2021-10-18 plq 医保上线移植
        /// </summary>
        /// <param name="info"></param>
        /// <param name="patientChargeLogInfo"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool MobileSavePatientCharge(string TaskCode, int PatientOrder, M_PatientCharge info, M_PatientChargeLog patientChargeLogInfo, List<M_PatientChargeDetail> patientChargeDetailInfo, List<M_PatientChargeDetailLog> patientChargeDetailLogInfo, bool Isvalid, ref string errorMsg)
        {
            //2018-12-11 zch 
            if (info != null && info.InvoiceNumber != null)
            {
                new I_InvoiceApprovalBLL().DealUsedInvoiceRecord(info.InvoiceNumber);
            }
            //return idal.MobileSavePatientCharge(info, patientChargeLogInfo, ref errorMsg);
            return idal.MobileSavePatientCharge(TaskCode, PatientOrder, info, patientChargeLogInfo, patientChargeDetailInfo, patientChargeDetailLogInfo, Isvalid, ref errorMsg);

        }

        //20151210增加PAD根据任务编码序号查询收费主表信息
        //20211025 zll 增加收费子表回传  //2021-12-06 plq 医保移植
        public void GetPatientChargeInfo(string taskCode, int patientOrder, out M_PatientCharge info, out List<M_PatientChargeDetail> pcDetail)
        {
            idal.GetPatientChargeInfo(taskCode, patientOrder, out info, out pcDetail);
        }

        //20151211增加PAD新增病历信息
        public bool InsertPAD(object info, M_PatientRecordAppend pra
            , M_PatientRecordCPR prCPR, List<M_PatientRecordDiag> prDiag
            , List<M_PatientRecordECGImpressions> prECG
            , List<M_PatientRecordRescue> prRescue, List<M_PatientRecordMeasure> prMeasure
            , List<M_PatientRecordDrug> prDrug, List<M_PatientRecordSanitation> prSanitation
            , List<M_PatientRecordLossDrug> prLossDrug, List<M_PatientRecordLossSanitation> prLossSanitation)
        {
            return idal.InsertPAD(info, pra, prCPR, prDiag, prECG, prRescue
                , prMeasure, prDrug, prSanitation, prLossDrug, prLossSanitation);
        }

        //20151211增加PAD修改病历信息
        public bool UpdatePAD(object info, M_PatientRecordAppend pra
            , M_PatientRecordCPR prCPR, List<M_PatientRecordDiag> prDiag
            , List<M_PatientRecordECGImpressions> prECG
            , List<M_PatientRecordRescue> prRescue, List<M_PatientRecordMeasure> prMeasure
            , List<M_PatientRecordDrug> prDrug, List<M_PatientRecordSanitation> prSanitation
            , List<M_PatientRecordLossDrug> prLossDrug, List<M_PatientRecordLossSanitation> prLossSanitation)
        {
            return idal.UpdatePAD(info, pra, prCPR, prDiag, prECG, prRescue
                , prMeasure, prDrug, prSanitation, prLossDrug, prLossSanitation);
        }

        //根据工号获取中心编码
        public void GetCenterCode(string workCode, out string centerCode)
        {
            idal.GetCenterCode(workCode, out centerCode);
        }

        public List<MobileTaskInfo> GetMobileTaskListsBy(string begintime, string endtime, string centerCode, string taskOrder, ref string errorMsg)
        {
            return idal.GetMobileTaskListsBy(begintime, endtime, centerCode, taskOrder, ref errorMsg);
        }

        //20160421更新发票号
        public bool UpdateFaPiaoNumber(string TaskCode, int PatientOrder, string FaPiaoNumber)
        {
            return idal.UpdateFaPiaoNumber(TaskCode, PatientOrder, FaPiaoNumber);

        }

        ////2016-12-22 zch 单任务对多病历方式 业务逻辑
        //public List<MobileTaskInfo> getMobileTaskList(string userCode, string taskCode, ref string errorMsg)
        //{
        //    //根据userCode 先取任务表中前10条的任务信息.
        //    List<MobileTaskInfo> listTask = idal.GetMobileTaskListPOCO(userCode, taskCode, ref errorMsg);

        //    //再根据任务编码去遍历病历表中的信息. 
        //    foreach (MobileTaskInfo infoTask in listTask)
        //    {
        //        if (idal.getMobilePRSubmit(infoTask.RenWuBianMa))
        //        {
        //            listTask.Remove(infoTask); //将已提交的剔除掉
        //        }
        //    }
        //    //如果有一条未提交的就保留,全提交的就舍弃, 使用一个bool值来判断.



        // }



        //2020-04-10 zch
        public int DeleteTaskImg(string taskCode, int typeCode, int PatientOrder)
        {
            if (taskCode == "")
                return -1;
            else
                return idal.DeleteTaskImg(taskCode, typeCode, PatientOrder);

        }

        #region 移动支付 add2022-01-13 plq 从闵行移植

        #region 20200813 sr 支付订单信息新增以及修改操作
        //新增订单信息 
        public void Insert(string danhao, string taskcode, int patientorder, string workcode, string paytype, double jine, DateTime generationtime, string endtime, bool ifrefund, int result, string remark, string callorder, string invoicenumber, string patientname, int cancelresult)
        {
            idal.Insert(danhao, taskcode, patientorder, workcode, paytype, jine
                          , generationtime, endtime, ifrefund, result
                          , remark, callorder, invoicenumber, patientname, cancelresult);
        }
        #endregion

        //更新M_PatientPayRecord表的交易结果字段
        public void Update(string outtradeno, int result, string endtime, string paytype)
        {
            idal.Update(outtradeno, result, endtime, paytype);
        }
        //更新撤销结果
        public void UpdateCancelResult(string outtradeno, int cancelresult, string endtime)
        {
            idal.UpdateCancelResult(outtradeno, cancelresult, endtime);
        }

        public void InsetCancelResult(string outtradeno, string outrefundno, string work_code, string endtime)
        {
            idal.InsetCancelResult(outtradeno, outrefundno, work_code, endtime);
        }

        public bool ISRefund(string outtradeno, ref string refundno)
        {
            return idal.ISRefund(outtradeno, ref refundno);
        }

        public void GetTradeNo(string task_code, int patient_order, out string outtradeno)
        {
            idal.GetTradeNo(task_code, patient_order, out outtradeno);
        }

        #endregion


        public void GetYBZdList(string taskCode, int patientOrder, string code, out List<M_ZICDNew> zdnos, out string result)
        {
            idal.GetYBZdList(taskCode, patientOrder, code, out zdnos, out result);
        }


    }
}
